﻿@using Presentation.Web.Admin
@model Infrastructure.Crosscutting.Authorize.Dto.UserRoleDto
@{
    ViewBag.subtitle = "修改用户角色";
    ViewBag.Title = "修改用户角色";
    var roleService = DependencyResolver.Current.GetService<Infrastructure.Crosscutting.Authorize.IRoleService>();
    var roleList = roleService.GetList();
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Ajax.BeginForm("edit", "userrole", new AjaxOptions
{
    HttpMethod = "post",
    OnBegin = "checkedEditForm",
    OnFailure = "editFailure",
    OnSuccess = "editSuccess"
}))
{
    @Html.ValidationSummary(true)
    <fieldset class="module width_full">
        <legend></legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.UserName)
        </div>
        <div class="editor-field">
            @Html.TextBox("UserName", Model.UserName, new { @readonly = "readonly" })
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.RoleName)
        </div>
        <div class="editor-field">
            <select id="RoleId" name="RoleId">
                <option value = "0">----请选择----</option>
                @{
    foreach (var item in roleList)
    {
                    <option  value = "@(item.Id)" @((Model != null && Model.RoleId == item.Id) ? "selected='selecetd'" : "")>@(item.Name)</option>
    }
                }
            </select>
        </div>
        <div style="display: none;">
            @Html.HiddenFor(model => model.Id)
            @Html.HiddenFor(model => model.AddTime)
            @Html.HiddenFor(model => model.IpAddress)
            @Html.HiddenFor(model => model.UserId)
            @Html.HiddenFor(model => model.RoleId)
            @Html.HiddenFor(model => model.State)
            @Html.HiddenFor(model => model.SortNum)
        </div>
    </fieldset> 
    <p>
        <input type="submit" value="修改" class="alt_btn module_margin" />@Html.GoBackPre("t-button")
    </p>
}
<script type="text/javascript">
    function checkedEditForm() {
        var res = true;
        return res;
    }

    function editSuccess(res) {
        if (res.success) {
            alert("修改成功");
        }
        else {
            alert(res.message);
        }
    }

    function editFailure() {
        alert("修改失败了T_T！");
    }
</script>